using System;
using UnityEngine;
using UnityEngine.UI;

public class NumController: MonoBehaviour
{
    public NumShow coinText;
    public NumShow diamondText;

    private void Start()
    {
        MGameUser gameUser = null;
        if (MGame.instance)
            gameUser = MGame.instance.MUser;
        else
            gameUser = GetComponentInParent<MBattleSceneController>().gameUser;
        
        Init(gameUser);
    }

    public void Init(GameUser user)
    {
        GameUser.onUpdateCoin += UpdateCoinText;
        GameUser.onUpdateDiamond += UpdateDiamondText;

        coinText.Init(user.coin,"","",0);
        //UpdateCoinText(user.diamond);
    }

    void UpdateCoinText(float coin)
    {
        if(coinText)
            this.coinText.num = coin;
    }
    
    
    void UpdateDiamondText(int diamond)
    {
        if(diamondText)
            this.diamondText.num = diamond;


    }

    private void OnDestroy()
    {
        GameUser.onUpdateCoin -= UpdateCoinText;
        GameUser.onUpdateDiamond -= UpdateDiamondText;
    }
}